//
//  QueryShuttleViewController.m
//  Logistics
//
//  Created by 华谕 on 2017/11/2.
//  Copyright © 2017年 HUYU. All rights reserved.
//

#import "QueryShuttleViewController.h"
#import "SpecialLineModel.h"
#import "CompanyLineModel.h"
#import "CloseAreaViewController.h"
#import "GoodLineViewController.h"
#import "CompanyHomeViewController.h"

static NSString *cellPath = @"specLineCELL";
@interface QueryShuttleViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    UILabel *deliveryLab;
    UILabel *goodsLab;
}
@property (nonatomic, strong)UITableView *tableview;
@property (nonatomic, assign)NSInteger page;
//@property (nonatomic, strong)NSMutableArray *speciaAry; //全部
@property (nonatomic, strong)NSMutableArray *certifiedAry; //已认证
@property (nonatomic, strong)NSMutableArray *unauthorAry; //未认证
@property (nonatomic, strong)NSString *wlPhone;
@property (nonatomic, strong)SpecialLineModel *speciModel;

@end

@implementation QueryShuttleViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    NSNotificationCenter * center = [NSNotificationCenter defaultCenter];
    [center addObserver:self selector:@selector(callPhonesNotifice:) name:@"callPhones" object:nil];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"callPhones" object:nil];
}


- (void)callPhonesNotifice:(NSNotification *)center
{
    NSString *timeStr = [center object];
    if (_speciModel)
    {
        Student *stu = [Student studentWith:_speciModel.companyLogo name:_speciModel.companyNameShort Phone:_speciModel.phone Times:timeStr];
        BOOL isInsert = [StudentFMDNManager addStudent:stu];
        if (isInsert) {
            NSLog(@"插入成功");
        } else {
            NSLog(@"插入失败");
        }
        _speciModel = nil;
    }
    else
    {
        Student *stu = [Student studentWith:@"" name:@"专线网" Phone:_wlPhone Times:timeStr];
        BOOL isInsert = [StudentFMDNManager addStudent:stu];
        if (isInsert) {
            NSLog(@"插入成功");
        } else {
            NSLog(@"插入失败");
        }
    }
    
    
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    _page = 0;
    _wlPhone = @"";
    [self requestServicePhone];

//    _speciaAry = [NSMutableArray arrayWithCapacity:0];
    _certifiedAry = [NSMutableArray arrayWithCapacity:0];
    _unauthorAry = [NSMutableArray arrayWithCapacity:0];
    [self creatUI];
    
    [self requestStationLine];
}

- (void)creatUI
{
    self.view.backgroundColor = RGB(245, 245, 245);
    self.navigationController.navigationBar.translucent = NO;
    self.navigationItem.title = @"专线网 - 查专线";
    UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 60*displayheight)];
    backView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:backView];
    UIButton *deliveryBtn = [ZCControl createButtonWithFrame:CGRectMake(15*displaywidth, 10*displayheight, 120*displaywidth, 15*displayheight) ImageName:@"sy_icon01" Target:self Action:@selector(deliveryAction) Title:@" 发货城市" Font:13.0];
    [deliveryBtn setTitleColor:RGB(153, 153, 153) forState:UIControlStateNormal];
    deliveryBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    deliveryBtn.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    [backView addSubview:deliveryBtn];
    
    UIButton *goodsBtn = [ZCControl createButtonWithFrame:CGRectMake(SCREEN_WIDTH- 135*displaywidth, 10*displayheight, 120*displaywidth, 15*displayheight) ImageName:@"sy_icon02" Target:self Action:@selector(goodsAction) Title:@" 收货城市" Font:13.0];
    [goodsBtn setTitleColor:RGB(153, 153, 153) forState:UIControlStateNormal];
    goodsBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    goodsBtn.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    [backView addSubview:goodsBtn];
    
    UIImageView *contImgView = [ZCControl createImageViewWithFrame:CGRectMake(SCREEN_WIDTH/2-20*displayheight, 20*displayheight, 40*displayheight, 40*displayheight) ImageName:@"sy_icon03"];
    contImgView.contentMode = UIViewContentModeScaleAspectFit;
    [backView addSubview:contImgView];
    
    deliveryLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 25*displayheight, SCREEN_WIDTH/2-40*displaywidth, 35*displayheight) Font:21.0 Text:_startCity Color:RGB(48, 48, 48)];
    [backView addSubview:deliveryLab];
    goodsLab = [ZCControl createLabelWithFrame:CGRectMake(SCREEN_WIDTH/2+ 25*displaywidth, 25*displayheight, SCREEN_WIDTH/2-40*displaywidth, 35*displayheight) Font:21.0 Text:_stopCity Color:RGB(48, 48, 48)];
    goodsLab.textAlignment = NSTextAlignmentRight;
    [backView addSubview:goodsLab];
    self.tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, 60*displayheight, SCREEN_WIDTH, SCREEN_HEIGHT-STA_NAV_HEIGHT-120*displayheight-SCREER_HeiX) style:UITableViewStylePlain];
    _tableview.delegate = self;
    _tableview.dataSource = self;
    _tableview.backgroundColor = RGB(245, 245, 245);
    _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:_tableview];

    self.tableview.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewHeaderData)];
    self.tableview.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreFootData)];
    self.tableview.mj_footer.automaticallyHidden = YES;
    self.tableview.estimatedRowHeight = 0;
    self.tableview.estimatedSectionHeaderHeight = 0;
    self.tableview.estimatedSectionFooterHeight = 0;
    UIView *bottomViews = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT-STA_NAV_HEIGHT-60*displayheight-SCREER_HeiX, SCREEN_WIDTH, 60*displayheight)];
    bottomViews.backgroundColor = RGB(245, 245, 245);
    [self.view addSubview:bottomViews];
    UIButton *contactBtn = [ZCControl createButtonWithFrame:CGRectMake(25*displaywidth, 15*displayheight, SCREEN_WIDTH/2-25*displaywidth, 30*displayheight) ImageName:@"tel" Target:self Action:@selector(contactAction) Title:@" 联系专线网" Font:13.0];
    contactBtn.backgroundColor = [UIColor clearColor];
    [contactBtn setTitleColor:ThemeColor forState:UIControlStateNormal];
    contactBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    contactBtn.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    [bottomViews addSubview:contactBtn];
    
    UIButton *recomBtn = [ZCControl createButtonWithFrame:CGRectMake(SCREEN_WIDTH/2,  15*displayheight, SCREEN_WIDTH/2-25*displaywidth, 30*displayheight) ImageName:@"tel" Target:self Action:@selector(recomAction) Title:@" 推荐优质专线" Font:13.0];
    recomBtn.backgroundColor = [UIColor clearColor];
    [recomBtn setTitleColor:ThemeColor forState:UIControlStateNormal];
    recomBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    recomBtn.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    [bottomViews addSubview:recomBtn];
}

- (void)loadNewHeaderData
{
    _page = 0;
    [self requestStationLine];

}

- (void)loadMoreFootData
{
    _page ++;
    [self requestStationLine];

}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0)
    {
        return _certifiedAry.count;
    }
    return _unauthorAry.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellPath];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (indexPath.section == 0)
    {
        cell.backgroundColor = [UIColor whiteColor];
        if (_certifiedAry.count > 0)
        {
            SpecialLineModel *model = _certifiedAry[indexPath.row];
            NSArray *comLineAry = model.companyLines;
            UIImageView *imgView = [ZCControl createImageViewWithFrame:CGRectMake(15*displaywidth, 10*displayheight, 90*displaywidth, 60*displayheight) ImageName:nil];
            if (model.companyLogo)
            {
                 [imgView sd_setImageWithURL:[NSURL URLWithString:model.companyLogo] placeholderImage:[UIImage imageNamed:@"newsImage"]];
            }
            imgView.contentMode = UIViewContentModeScaleAspectFill;
            imgView.layer.masksToBounds = YES;
            [cell.contentView addSubview:imgView];
            
            UILabel *comNameLab = [ZCControl createLabelWithFrame:CGRectMake(115*displaywidth, 10*displayheight, 100*displaywidth, 25*displayheight) Font:15.0 Text:model.companyNameShort Color:[UIColor blackColor]];
            comNameLab.textAlignment = NSTextAlignmentLeft;
            [cell.contentView addSubview:comNameLab];
            CGRect bounds = [comNameLab.text boundingRectWithSize:CGSizeMake(500*displaywidth, 25*displayheight) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:NormalFontWithSize(15.0+fontScale) forKey:NSFontAttributeName] context:nil];
            CGFloat widrh = bounds.size.width;
            if (widrh > SCREEN_WIDTH-220*displaywidth)
            {
                widrh = SCREEN_WIDTH-220*displaywidth;
            }
            comNameLab.frame = CGRectMake(115*displaywidth, 10*displayheight, widrh, 25*displayheight);
            widrh+=120*displaywidth;
            if ([model.shi integerValue] == 1)
            {
                UILabel *shiLab = [ZCControl createLabelWithFrame:CGRectMake(widrh, 16.5*displayheight, 10*displaywidth, 10*displayheight) Font:10.0 Text:@"实" Color:[UIColor whiteColor]];
                shiLab.backgroundColor = RGB(204, 153, 102);
                shiLab.textAlignment = NSTextAlignmentCenter;
                [cell.contentView addSubview:shiLab];
                widrh+=15*displaywidth;
            }
            if ([model.bao integerValue] == 1)
            {
                UILabel *baoLab = [ZCControl createLabelWithFrame:CGRectMake(widrh, 16.5*displayheight, 10*displaywidth, 10*displayheight) Font:10.0 Text:@"保" Color:[UIColor whiteColor]];
                baoLab.backgroundColor = RGB(0, 153, 255);
                baoLab.textAlignment = NSTextAlignmentCenter;
                [cell.contentView addSubview:baoLab];
            }
            CGFloat HEIGHT = 35*displayheight;

            if (comLineAry.count > 0)
            {
                for (int i = 0; i < comLineAry.count; i++)
                {
                    if (comLineAry.count > 2 && i == 1)
                    {
                        if (!model.isShow)
                        {
                            UIButton *showBtn = [ZCControl createButtonWithFrame:CGRectMake(115*displaywidth, 55*displayheight, SCREEN_WIDTH-175*displaywidth, 20*displayheight) ImageName:nil Target:self Action:@selector(showAction:) Title:@"含有多条线路，点击展开" Font:11.0];
                            showBtn.tag = indexPath.row + 100;
                            [showBtn setTitleColor:ThemeColor forState:UIControlStateNormal];
                            showBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
                            showBtn.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
                            [cell.contentView addSubview:showBtn];
                            HEIGHT+=20*displayheight;
                            break;
                        }
                        else
                        {
                            UIButton *showBtn = [ZCControl createButtonWithFrame:CGRectMake(15*displaywidth, 70*displayheight, 90*displaywidth, 20*displayheight) ImageName:nil Target:self Action:@selector(showAction:) Title:@"点击收回" Font:11.0];
                            showBtn.tag = indexPath.row + 100;
                            [showBtn setTitleColor:ThemeColor forState:UIControlStateNormal];
                            [cell.contentView addSubview:showBtn];
                        }
                    }
                    CompanyLineModel *companyModel = comLineAry[i];
                    UILabel *startLab = [ZCControl createLabelWithFrame:CGRectMake(115*displaywidth, 35*displayheight+i*20*displayheight, 100*displaywidth, 20*displayheight) Font:13.0 Text:companyModel.shipName Color:RGB(102, 102, 102)];
                    startLab.textAlignment = NSTextAlignmentLeft;
                    [cell.contentView addSubview:startLab];
                    CGRect bound1 = [startLab.text boundingRectWithSize:CGSizeMake(500*displaywidth, 25*displayheight) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:NormalFontWithSize(13.0+fontScale) forKey:NSFontAttributeName] context:nil];
                    CGFloat W = bound1.size.width+5*displaywidth;
                    startLab.frame = CGRectMake(115*displaywidth, 35*displayheight +i*20*displayheight, W, 20*displayheight);
                    W+=120*displaywidth;
                    UIImageView *zhiXimgView = [ZCControl createImageViewWithFrame:CGRectMake(W, 40*displaywidth+i*20*displayheight, 30*displaywidth, 10*displayheight) ImageName:@"zxli_icon01"];
                    zhiXimgView.contentMode = UIViewContentModeScaleAspectFit;
                    [cell.contentView addSubview:zhiXimgView];
                    W+=35*displaywidth;
                    UILabel *stopLab = [ZCControl createLabelWithFrame:CGRectMake(W, 35*displayheight+i*20*displayheight, 100*displaywidth, 20*displayheight) Font:13.0 Text:companyModel.distName Color:RGB(102, 102, 102)];
                    stopLab.textAlignment = NSTextAlignmentLeft;
                    [cell.contentView addSubview:stopLab];
                    CGRect bound2 = [stopLab.text boundingRectWithSize:CGSizeMake(500*displaywidth, 25*displayheight) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:NormalFontWithSize(13.0+fontScale) forKey:NSFontAttributeName] context:nil];
                    stopLab.frame = CGRectMake(W, 35*displayheight+i*20*displayheight, bound2.size.width+5*displaywidth, 20*displayheight);
                    W+= (bound2.size.width+5*displaywidth);
                    if (companyModel.describes.length > 0)
                    {
                        UILabel *zhidaLab = [ZCControl createLabelWithFrame:CGRectMake(W, 37.5*displayheight+i*20*displayheight, 100*displaywidth, 15*displayheight) Font:9.0 Text:companyModel.describes Color:RGB(255, 153, 20)];
                        zhidaLab.textAlignment = NSTextAlignmentCenter;
                        zhidaLab.backgroundColor = [UIColor whiteColor];
                        zhidaLab.layer.cornerRadius = 3;
                        zhidaLab.layer.masksToBounds = YES;
                        zhidaLab.layer.borderWidth = 1;
                        zhidaLab.layer.borderColor = RGB(255, 153, 20).CGColor;
                        [cell.contentView addSubview:zhidaLab];
                        CGRect bound3 = [zhidaLab.text boundingRectWithSize:CGSizeMake(500*displaywidth, 15*displayheight) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:NormalFontWithSize(9.0+fontScale) forKey:NSFontAttributeName] context:nil];
                        zhidaLab.frame = CGRectMake(W, 37.5*displayheight+i*20*displayheight, bound3.size.width+10*displaywidth, 15*displayheight);
                         W+= (bound3.size.width+15*displaywidth);
//                        if (W > SCREEN_WIDTH-50*displaywidth)
//                        {
//                            zhidaLab.hidden = YES;
//                        }
//                        else
//                        {
//                            CGFloat windTH = bound3.size.width+10*displaywidth;
//                            if ([companyModel.jian integerValue] == 1)
//                            {
//                                windTH+=20*displaywidth;
//                            }
//                            if ((W + windTH) > SCREEN_WIDTH-50*displaywidth)
//                            {
//                                zhidaLab.frame = CGRectMake(W, 37.5*displayheight, SCREEN_WIDTH-70*displaywidth-W, 15*displayheight);
//
//                            }
//                            else
//                            {
//                                W+= (bound3.size.width+15*displaywidth);
//
//                            }
//                            
//                        }
                    }
                    if ([companyModel.jian integerValue] == 1)
                    {
                        UILabel *baoLab = [ZCControl createLabelWithFrame:CGRectMake(W, 40*displayheight+i*20*displayheight, 10*displaywidth, 10*displayheight) Font:10.0 Text:@"荐" Color:[UIColor whiteColor]];
                        baoLab.backgroundColor = RGB(25, 169, 123);
                        [cell.contentView addSubview:baoLab];
                        W+=10*displaywidth;
                        if (W > SCREEN_WIDTH-50*displaywidth)
                        {
                            baoLab.hidden = YES;
                        }
                    }
                    HEIGHT+=20*displayheight;
                }
                
                
            }
            UIButton *callBtn = [ZCControl createButtonWithFrame:CGRectMake(SCREEN_WIDTH-50*displaywidth, 20*displayheight, 30*displayheight, 30*displayheight) ImageName:@"bigtel" Target:self Action:@selector(callPhoneAction:) Title:nil Font:12.0];
            callBtn.tag = indexPath.row + 3000;
            [cell.contentView addSubview:callBtn];
            UILabel *addressLab = [ZCControl createLabelWithFrame:CGRectMake(115*displaywidth, HEIGHT, SCREEN_WIDTH-190*displaywidth, 20*displayheight) Font:11.0 Text:model.stationAddress Color:RGB(154, 154, 154)];
            addressLab.textAlignment = NSTextAlignmentLeft;
            [cell.contentView addSubview:addressLab];
            CGFloat distance = [model.distance floatValue]/1000.0;
            NSString *string = [NSString stringWithFormat:@"%.1lfkm",distance];
            if (distance == 0)
            {
                string = @"0km";
            }
            UILabel *distanceLab = [ZCControl createLabelWithFrame:CGRectMake(SCREEN_WIDTH-75*displaywidth, HEIGHT, 60*displaywidth, 20*displayheight) Font:11.0 Text:string Color:RGB(154, 154, 154)];
            distanceLab.textAlignment = NSTextAlignmentRight;
            [cell.contentView addSubview:distanceLab];
            UIView *lineview = [[UIView alloc] initWithFrame:CGRectMake(0, HEIGHT+25*displayheight, SCREEN_WIDTH, 10*displayheight)];
            lineview.backgroundColor = RGB(245, 245, 245);
            [cell.contentView addSubview:lineview];
        }
        
    }
    else
    {
        SpecialLineModel *model = _unauthorAry[indexPath.row];
        NSString *name = model.companyNameShort;
        if (name.length > 0)
        {
            name = [model.companyNameShort substringToIndex:1];
        }
        UILabel *imgLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 12.5*displayheight, 35*displaywidth, 35*displayheight) Font:18.0 Text:name Color:RGB(170, 170, 170)];
        imgLab.textAlignment = NSTextAlignmentCenter;
        imgLab.backgroundColor = RGB(235, 235, 235);
        [cell.contentView addSubview:imgLab];
        
        UILabel *comNameLab = [ZCControl createLabelWithFrame:CGRectMake(60*displaywidth, 10*displayheight, SCREEN_WIDTH/2-65*displaywidth, 40*displayheight) Font:15.0 Text:model.companyNameShort Color:[UIColor blackColor]];
        comNameLab.textAlignment = NSTextAlignmentLeft;
        [cell.contentView addSubview:comNameLab];
        
        UIButton *phoneBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        phoneBtn.backgroundColor = RGB(255, 247, 237);
        phoneBtn.frame = CGRectMake(SCREEN_WIDTH-180*displaywidth, 17.5*displayheight, 160*displaywidth, 25*displayheight);
        [phoneBtn setImage:[UIImage imageNamed:@"tel2"] forState:UIControlStateNormal];
        phoneBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        [phoneBtn setTitleColor:RGB(187, 176, 170) forState:UIControlStateNormal];
        [phoneBtn setTitle:model.phone forState:UIControlStateNormal];
        [phoneBtn addTarget:self action:@selector(phoneBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        CGSize imgSize = phoneBtn.currentImage.size;
        CGSize titleSize = [phoneBtn.titleLabel.text sizeWithAttributes:@{NSFontAttributeName:phoneBtn.titleLabel.font}];
        UIEdgeInsets   titleEdgeInsets = UIEdgeInsetsMake(0, -imgSize.width-5, 0, imgSize.width+10);
        UIEdgeInsets imgEdgeInsets = UIEdgeInsetsMake(0, 5+titleSize.width, 0, -titleSize.width+5);
        phoneBtn.titleEdgeInsets = titleEdgeInsets;
        phoneBtn.imageEdgeInsets = imgEdgeInsets;
        phoneBtn.layer.cornerRadius = 12.5*displayheight;
        phoneBtn.layer.borderWidth = 1;
        phoneBtn.layer.borderColor = RGBA(255, 153, 20, 0.34).CGColor;
        phoneBtn.layer.masksToBounds = YES;
        phoneBtn.tag = 6000+indexPath.row;
        phoneBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        phoneBtn.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
        phoneBtn.frame = CGRectMake(SCREEN_WIDTH- (imgSize.width+titleSize.width+20*displaywidth)-20*displaywidth, 17.5*displaywidth, imgSize.width+titleSize.width+20*displaywidth, 25*displaywidth);
        [cell.contentView addSubview:phoneBtn];
        UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 60*displayheight, SCREEN_WIDTH, 10*displayheight)];
        line.backgroundColor = RGB(245, 245, 245);
        [cell.contentView addSubview:line];
        
        
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)
    {
        SpecialLineModel *comModel = _certifiedAry[indexPath.row];
        CompanyHomeViewController *vc = [[CompanyHomeViewController alloc] init];
        vc.comPanyId = [NSString stringWithFormat:@"%ld",comModel.companyId];
        [self.navigationController pushViewController:vc animated:YES];
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)
    {
        SpecialLineModel *model = _certifiedAry[indexPath.row];
        NSArray *comLineAry = model.companyLines;
        if (comLineAry.count >= 2)
        {
            CGFloat h = 110*displayheight;
            if (model.isShow)
            {
                h = comLineAry.count*20*displayheight+70*displayheight;
            }
            return h;
        }
        
        return 90*displayheight;
    }
    return 70*displayheight;
}

//选择发货城市
- (void)deliveryAction
{
    CloseAreaViewController *vc = [[CloseAreaViewController alloc] init];
    vc.areaType = 1;
    WEAKSELF;
    vc.closeBlock = ^(NSString *city, NSString *areaId)
    {
        weakSelf.startCity = city;
        weakSelf.startCityId = areaId;
        dispatch_async(dispatch_get_main_queue(), ^{
            deliveryLab.text = city;
        });
        
    };
    [self.navigationController pushViewController:vc animated:YES];
    
}

//选择收货城市
- (void)goodsAction
{
    CloseAreaViewController *vc = [[CloseAreaViewController alloc] init];
    vc.areaType = 2;
    vc.shipmentId = _startCityId;
    WEAKSELF;
    vc.closeBlock = ^(NSString *city, NSString *areaId)
    {
        weakSelf.stopCity = city;
        weakSelf.stopCityId = areaId;
        _page = 0;
        [self requestStationLine];
        dispatch_async(dispatch_get_main_queue(), ^{
            goodsLab.text = city;
            
        });
        
    };
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)phoneBtnAction:(UIButton *)btn
{
    NSInteger index = btn.tag-6000;
    SpecialLineModel *model = _unauthorAry[index];
    _speciModel = model;
    NSMutableString* str= [[NSMutableString alloc] initWithFormat:@"telprompt://%@",model.phone];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
    
    
}

- (void)callPhoneAction:(UIButton *)btn
{
    NSInteger index = btn.tag-3000;
    SpecialLineModel *model = _certifiedAry[index];
    _speciModel = model;
    NSMutableString* str= [[NSMutableString alloc] initWithFormat:@"telprompt://%@",model.phone];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
}

//联系专线网
- (void)contactAction
{
    if ([_wlPhone isEqualToString:@""])
    {
        [self requestServicePhone];
        return;
    }
    NSMutableString* str= [[NSMutableString alloc] initWithFormat:@"telprompt://%@",_wlPhone];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
}

//推荐优质专线
- (void)recomAction
{
    GoodLineViewController *vc = [[GoodLineViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

//展开线路
- (void)showAction:(UIButton *)btn
{
    NSInteger index = btn.tag-100;
    SpecialLineModel *model = _certifiedAry[index];
    model.isShow = !model.isShow;
    [self.tableview reloadData];

}


- (void)requestStationLine
{
    NSDictionary *dic = @{@"shipmentId":_startCityId,
                          @"destinationId":_stopCityId,
                          @"lng":_lngStr,
                          @"lat":_latStr,
                          @"size":@"20",
                          @"page":[NSString stringWithFormat:@"%ld",_page]
                          };
    WEAKSELF;
    [HYBaseHandler requestStationLineParmers:dic Success:^(id obj) {
        if ([obj server_Getcodecheck])
        {
            NSArray *contentAry = obj[@"data"][@"content"];
            if (contentAry.count > 0)
            {
                if (_page == 0)
                {
                    [weakSelf.certifiedAry removeAllObjects];
                    [weakSelf.unauthorAry removeAllObjects];

                }
                for (NSDictionary *dic in contentAry)
                {
                    SpecialLineModel *speModel = [SpecialLineModel mj_objectWithKeyValues:dic];
                    if ([speModel.zheng integerValue] == 1)
                    {
                        [weakSelf.certifiedAry addObject:speModel];
                    }
                    else
                    {
                        [weakSelf.unauthorAry addObject:speModel];
                    }
                }
            }
            dispatch_async(dispatch_get_main_queue(), ^{
                [weakSelf.tableview reloadData];
            });
        }
        else
        {
            [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
        }
        [weakSelf.tableview.mj_header endRefreshing];
        [weakSelf.tableview.mj_footer endRefreshing];

    } failed:^(NSError *error) {
        [weakSelf.tableview.mj_header endRefreshing];
        [weakSelf.tableview.mj_footer endRefreshing];

    }];
}

- (void)requestServicePhone
{
    WEAKSELF;
    [HYBaseHandler requestServicePhoneParmers:nil Success:^(id obj) {
        if ([obj server_Getcodecheck])
        {
            weakSelf.wlPhone = [NSString stringWithFormat:@"%@",obj[@"data"]];
        }
        else
        {
            [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
        }
    } failed:^(NSError *error) {
        
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
